{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "class class_name(object):\n",
    "    class_var = 'I am a class variable' #类变量\n",
    "    def __init__(self):\n",
    "        self.instance_var = 'I am a instance varibale'  #成员变量（实例变量）\n",
    "\n",
    "    def instance_method(self,  formal_parameter):\n",
    "        local_var_in_function = formal_parameter    #实例方法局部变量\n",
    "        self.local_var_also_in_function = formal_parameter  #实例方法局部变量\n",
    "\n",
    "    def ordinary_function(formal_parameter):\n",
    "        print \"I am an ordinary function, I can't vist class var and intance var\"\n",
    "        print self.instance_var #报错，因此普通函数无法访问成员函数\n",
    "        print clacc_var#报错，因此普通函数无法访问类变量\n",
    "\n",
    "    @classmethod\n",
    "    def class_method(cls, formal_parameter): #类方法\n",
    "        print 'I am class method, I can visit class var and instance var'\n",
    "\n",
    "        print 'I am class method, I am modifying the instance var'\n",
    "        cls.instance_var = formal_parameter\n",
    "        print cls.instance_var\n",
    "\n",
    "        print 'I am class method, I am modifying the class var'\n",
    "        class_var = formal_parameter\n",
    "        print class_var\n",
    "\n",
    "    @staticmethod\n",
    "    def static_method(formal_parameter):\n",
    "        print 'I am static method, I am the Adopted son(干儿子) for this class!!'\n",
    "\n",
    "        print \"I can't modify anything in the class \"\n",
    "        #print class_var\n",
    "        #print self.instance_var"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
